import { SUB_NUMBER, ADD_NUMBER, INC_NUMBER, CHANGE_RECOMMEND, CHANGE_BANNERS, FETCH_HOME_MULTIDATA } from './constants.js'
import axios from 'axios'

export const addAction = (num) => {
  return {
    type: ADD_NUMBER,
    num
  }
}

export const subAction = (num) => {
  return {
    type: SUB_NUMBER,
    num
  }
}

export const incAction = () => {
  return {
    type: INC_NUMBER,
  }
}

// 轮播图 和 推荐的action
export const changeRecommendsAction = (recommends) => {
  return {
    type: CHANGE_RECOMMEND,
    recommends
  }
}

export const changeBannersAction = (banners) => {
  return {
    type: CHANGE_BANNERS,
    banners
  }
}

// redux-thunk定义的action函数
export const getHomeMultidataAction = (dispatch) => {
  axios({
    url: "http://123.207.32.32:8000/home/multidata",
  }).then(res => {
    const data = res.data.data;
    dispatch(changeBannersAction(data.banner.list))
    dispatch(changeRecommendsAction(data.recommend.list))
  })
}

export const fetchHomeMutidataAction = {
   type:FETCH_HOME_MULTIDATA
}